#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <fcntl.h>
#include "base.h"


int main(){

	struct sockaddr_in serverAddr;
	//socklen_t socklen;

	bzero(&serverAddr,sizeof(serverAddr));
//	serverAddr.sin_addr=htonl("127.0.0.1");
	inet_pton(AF_INET, "127.0.0.1", &serverAddr.sin_addr);
	serverAddr.sin_port=htons(SERVER_PORT);
	serverAddr.sin_family=AF_INET;

	char line[8];
	char rev[128];
	int clientFD;

	clientFD=socket(AF_INET,SOCK_STREAM,0);
	fcntl(clientFD, F_SETFL, fcntl(clientFD, F_GETFL, 0) | O_NONBLOCK);

	connect(clientFD,(struct sockaddr*)&serverAddr,sizeof(serverAddr));

	for(;;){
		scanf("%s",line);
		write(clientFD,line,8*sizeof(char));
		//read(clientFD,rev,128*sizeof(line));
		printf("%s\n",rev);
	}

	close(clientFD);
	exit(0);

}
